<script type="text/javascript"><!--//--><![CDATA[//><!--
var LOVJenisBarang = function(ao_option){
	try{
		if(ao_option==undefined){ ao_option={}; }
		var lf_onSelect	= (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
		
		// Create Popup
		var $popup	= openPopup({ title:'Daftar Jenis Barang' , width:700, height:370 });
		var ls_id	= $popup.attr('id');
		
		// Append Datagrid Container
		var ls_gridName	= 'grid_'+ls_id;
		$popup	.html(	$('<div>')	.attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
									.html(	$('<div>').html($('<form>')	.attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
																		.html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
															)
											)
						)
				.append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
		
		$('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
		$('#btn_search'+ls_id).linkbutton({  
			plain:true  
		}); 
		
		// Build Datagrid
		var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
		$('#'+ls_gridName).datagrid({  
			url:gs_path+'/mis_jenis_barang/getdata/'+ls_param,
			queryParams: $('#fm_search_'+ls_id).serializeObject(),
			height:337,
			pagination:true,
			singleSelect:true,
			columns:[[
				{ field : 'id_barang', title : 'ID Barang', width : 100, sortable:true },
				{ field : 'kode_jenis_barang', title : 'Kode Barang', width : 100, sortable:true },
				{ field : 'nama_jenis_barang', title : 'Nama Barang', width : 300, sortable:true }
				//{ field : 'kemasan', title : 'Kemasan', width:200, sortable:true },
				//{ field : 'isi', title : 'Isi', width:200, sortable:true }
			]],
			onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
		});
		
	} catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};
	
    $(document).ready(function() {

    	var id_perangkat_auto = '<?php echo $id_perangkat_auto; ?>'
    	var id_perangkat_edit = '<?php echo $id_perangkat_edit; ?>'

        // Setup Form
		$('#form_master').setupForm([
			{ name: 'kode_barang', type: 'lov', size: 'medium', noempty:true,
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_barang').setval('');
				
				},
				onActionButton:function(){ 
					LOVJenisBarang({ onSelect:function(row){
						$('#id_barang').setval(row.id_barang);
						$('#kode_barang').setval(row.kode_jenis_barang); 
						$('#nama_barang').setval(row.nama_jenis_barang); 
					} }); 
				}
			},
			{ name: 'nama_barang', type: 'text', size: 'long', maxlength: 100 , noempty:true},
			{ name: 'nama_merek', type: 'text', size: 'long', maxlength: 100 , noempty:true} ,
			{ name: 'spesifikasi', type: 'textarea', size:'medium', rows:3  },
			{ name: 'tipe', type: 'text', size: 'long', maxlength: 100},
			{ name: 'harga', type: 'text' , noempty:true},
			{ name: 'jumlah', type: 'text' , noempty:true},
			{ name: 'kondisi_barang', type: 'text', size: 'long', maxlength: 100 , noempty:true},
			{ name: 'keterangan', type: 'textarea', size:'medium', rows:3 }
        ], <?php echo json_encode($data); ?>);
        
//		f_set_combo_city_code();
		
		<?php if($mode=="create"){ ?>
        $('#id_perangkat').setval(id_perangkat_auto);
        $('#nama_barang').readonly();
        <?php } ?>

        <?php if($mode=="edit"){ ?>
       	var id_barang_edit = '<?php echo $id_barang_edit; ?>'
       	$('#id_barang').setval(id_barang_edit);
        $('#id_perangkat').setval(id_perangkat_edit);
        $('#kode_barang,#nama_barang').readonly();
        <?php } ?>
		
		// Set Action Button
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
							$('#form_master').submitForm(	'/'+controller+'/ajax_post', 
															{	/*detail:[{ table: 'dtl_sample2', field:['index_no','ref_key_combo','ref_key_lov','jumlah','keterangan']}
																		],*/ 
																onComplete : function(data){ eval('oData = '+data); loadPage('/'+controller+'/index/'); }
															} 
														);
							//loadPage(gs_path+'/'+controller+'/index');
						}},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/Index'); } }];
		setAction(buttons);
		
		// Create Tab
		$('#tt').tabs({ border:false });  
		
		// Focus at First Object
		$('#form_master').focusFirst();
    });
//--><!]]></script>

<div id="form_master_message" style="display:none;"></div>

<table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
	<tr>
    	<td>
    		<input id="id_perangkat" name="id_perangkat" type="hidden" />
    		<input id="id_barang" name="id_barang" type="hidden" />
    	</td>
	</tr>
	<tr>
		<td class="label">Kode Barang</td>
		<td><input id="kode_barang" /></td>
		<td class="label">Nama Merek</td>
		<td><input id="nama_merek" /></td>
	</tr>
	<tr>
		<td class="label">Nama Barang</td>
		<td><input id="nama_barang" /></td>
		<td class="label" rowspan="2">Spesifikasi</td>
		<td rowspan="2"><input id="spesifikasi" /></td>
	</tr>
	<tr>
		<td class="label">Tipe</td>
		<td><input id="tipe" /></td>
	</tr>
	<tr>
		<td class="label">Harga</td>
		<td><input id="harga" /></td>
	</tr>
	<tr>
		<td class="label">Jumlah</td>
		<td><input id="jumlah" /></td>
	</tr>
	<tr>
		<td class="label">Kondisi Barang</td>
		<td><input id="kondisi_barang" /></td>
	</tr>
	<tr>
		<td class="label" rowspan="2">Keterangan</td>
		<td rowspan="2"><input id="keterangan" /></td>
	</tr>
</table>

